<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class IndexController extends Controller
{
    // 前台首页
    public function layout()
    {
        $allData = DB::table('cate') -> orderby('nav_id', 'asc') -> get();
        $menuData = DB::table('cate') -> orderby('menu_id', 'asc') -> get();
    	$user = DB::table('users') -> get();
        

    	$data = DB::table('goods') -> orderby('id', 'asc') -> paginate(18);
    	
    	return view('home.index.layout', ['allData' => $allData, 'data' => $data, 'user' => $user, 'menudata' => $menuData]);
       
    }

    public function index()
    {

        $onedata = DB::table('cate') -> first();
        $addata = DB::table('ad')-> orderby('id', 'desc') -> first();
        //友情链接
        $linkData = DB::table('link') -> take('10') ->get();
        // 关键字
        $word = DB::table('word') -> get();   

        $allData = DB::table('cate') -> get();
        $menuData = DB::table('cate') -> orderby('menu_id', 'asc') -> get();
        $user = DB::table('users') -> get();        

        $data = DB::table('goods') -> where('status', '0') -> orderby('time', 'desc') ->paginate(18);        
       
        return view('home.index.index', ['onedata' => $onedata, 'allData' => $allData, 'data' => $data, 'user' => $user, 'menudata' => $menuData, 'addata' => $addata, 'linkData' => $linkData, 'word'=> $word]);
        
    }

    //分类列表
    public function catelist($id)
    {
        //友情链接
        $linkData = DB::table('link') -> take('10') ->get();
        // 关键字
        $word = DB::table('word') -> get();   
        $cateData = DB::table('cate')-> where('id', $id) -> first();
        $allData = DB::table('cate') -> orderby('nav_id', 'asc') -> get();
        $menuData = DB::table('cate') -> orderby('menu_id', 'asc') -> get();
        $user = DB::table('users') -> get();
        $data = DB::table('goods') -> where('cate_id', $id) -> orderby('time', 'desc') ->paginate(18);        
       // dd($allData);
        return view('home.index.list', ['allData' => $allData, 'data' => $data, 'user' => $user, 'menudata' => $menuData, 'cateData' => $cateData,'linkData' => $linkData, 'word'=> $word]);
       if($data && $allData)
       {
            
       }else
       {
            return back();
       }
        
        
    }

}
